package com.yuma.tingshu.order.service.impl;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yuma.tingshu.account.client.UserAccountFeignClient;
import com.yuma.tingshu.album.client.AlbumInfoFeignClient;
import com.yuma.tingshu.album.client.TrackInfoFeignClient;
import com.yuma.tingshu.common.constant.RabbitConstant;
import com.yuma.tingshu.common.constant.RedisConstant;
import com.yuma.tingshu.common.constant.SystemConstant;
import com.yuma.tingshu.common.execption.YumaException;
import com.yuma.tingshu.common.result.Result;
import com.yuma.tingshu.common.result.ResultCodeEnum;
import com.yuma.tingshu.common.util.AuthContextHolder;
import com.yuma.tingshu.model.order.OrderDerate;
import com.yuma.tingshu.model.order.OrderDetail;
import com.yuma.tingshu.model.order.OrderInfo;
import com.yuma.tingshu.order.helper.SignHelper;
import com.yuma.tingshu.order.mapper.OrderDerateMapper;
import com.yuma.tingshu.order.mapper.OrderDetailMapper;
import com.yuma.tingshu.order.mapper.OrderInfoMapper;
import com.yuma.tingshu.order.service.OrderInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yuma.tingshu.order.template.AlbumTrade;
import com.yuma.tingshu.order.template.TrackTrade;
import com.yuma.tingshu.order.template.VipTrade;
import com.yuma.tingshu.order.template.anno.TradeBeanClient;
import com.yuma.tingshu.user.client.UserInfoFeignClient;
import com.yuma.tingshu.user.client.VipServiceConfigFeignClient;
import com.yuma.tingshu.vo.account.AccountLockResultVo;
import com.yuma.tingshu.vo.account.AccountLockVo;
import com.yuma.tingshu.vo.order.OrderDerateVo;
import com.yuma.tingshu.vo.order.OrderDetailVo;
import com.yuma.tingshu.vo.order.OrderInfoVo;
import com.yuma.tingshu.vo.order.TradeVo;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.script.DefaultRedisScript;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Slf4j
@Service
@SuppressWarnings({"unchecked", "rawtypes"})
public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo> implements OrderInfoService {

    @Autowired
    private OrderInfoMapper orderInfoMapper;
    @Resource
    private VipServiceConfigFeignClient vipServiceConfigFeignClient;
    @Resource
    private UserInfoFeignClient userInfoFeignClient;
    @Resource
    private AlbumInfoFeignClient albumInfoFeignClient;
    @Resource
    private TrackInfoFeignClient trackInfoFeignClient;
    @Resource
    private VipTrade vipTrade;
    @Resource
    private AlbumTrade albumTrade;
    @Resource
    private TrackTrade trackTrade;
    @Resource
    private TradeBeanClient tradeBeanClient;
    @Autowired
    private UserAccountFeignClient userAccountFeignClient;
    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    private RabbitTemplate rabbitTemplate;
    @Autowired
    private OrderDetailMapper orderDetailMapper;
    @Autowired
    private OrderDerateMapper orderDerateMapper;

    @Override
    public Page<OrderInfo> findUserPage(Integer page, Integer limit) {
        // 1.判空
        if (page == null || limit == null) {
            throw new YumaException(ResultCodeEnum.ARGUMENT_VALID_ERROR);
        }
        // 2.获取当前用户ID
        Long userId = AuthContextHolder.getUserId();
        // 3.分页查找当前用户的所有的0rderInfo
        Page<OrderInfo> orderInfoPage = this.page(new Page<>(page, limit), new LambdaQueryWrapper<OrderInfo>()
                .eq(OrderInfo::getUserId, userId)
                .orderByDesc(OrderInfo::getId));
        // 4.判空
        if (orderInfoPage == null) {
            throw new RuntimeException("您还没有订单信息");
        }
        // 5.如果不为空获取page中的records
        List<OrderInfo> orderInfoRecords = orderInfoPage.getRecords();
        if (CollectionUtils.isEmpty(orderInfoPage.getRecords())) {
            throw new RuntimeException("您还没有订单信息");
        }
        // 6.设置详情封装(orderDetail,orderDerate部分数据)
        List<OrderInfo> list = orderInfoRecords.stream().map(orderInfo -> this.getOrderInfo(orderInfo.getOrderNo())).toList();
        // 7.重新设置给page的record
        orderInfoPage.setRecords(list);
        // 复用this.getOrderInfo(String orderNo),省略以下冗余代码
        /*orderInfoRecords.forEach(orderInfo -> {
            // 根据订单id查询订单详情
            List<OrderDetail> orderDetails = this.orderDetailMapper.selectList(new LambdaQueryWrapper<OrderDetail>()
                    .eq(OrderDetail::getOrderId, orderInfo.getId()));
            // 7.重新设置给page的record
            orderInfo.setOrderDetailList(orderDetails);
            // 根据订单id查询订单减免, 声音类型就不需要查了
            if (!SystemConstant.ORDER_ITEM_TYPE_TRACK.equals(orderInfo.getItemType())) {
                List<OrderDerate> orderDerates = this.orderDerateMapper.selectList(new LambdaQueryWrapper<OrderDerate>()
                        .eq(OrderDerate::getOrderId, orderInfo.getId()));
                // 7.重新设置给page的record
                orderInfo.setOrderDerateList(orderDerates);
            }
            // 支付中文名
            orderInfo.setPayWayName(getPayWayName(orderInfo.getPayWay()));
            orderInfo.setOrderStatusName(getOrderStatusName(orderInfo.getOrderStatus()));
        });*/
        // 8.返回page对象
        return orderInfoPage;
    }

    @Override
    public OrderInfo getOrderInfo(String orderNo) {
        // 1.判空
        if (StringUtils.isEmpty(orderNo)) {
            throw new YumaException(ResultCodeEnum.ARGUMENT_VALID_ERROR);
        }
        // 2.orderInfoMapper根据orderNo获取订单，一个订单对应一个订单号
        OrderInfo orderInfo = orderInfoMapper.selectOne(new LambdaQueryWrapper<OrderInfo>().eq(OrderInfo::getOrderNo, orderNo));
        // 3.orderInfo判空
        if (orderInfo == null) {
            throw new YumaException(ResultCodeEnum.DATA_ERROR);
        }
        // 4.不为空根据order_id在orderDetail中获取订单明细
        List<OrderDetail> orderDetailList = orderDetailMapper.selectList(new LambdaQueryWrapper<OrderDetail>().eq(OrderDetail::getOrderId, orderInfo.getId()));
        // 5.orderDetail不为空，则设置orderInfo中
        if (!CollectionUtils.isEmpty(orderDetailList)) {
            orderInfo.setOrderDetailList(orderDetailList);
        }
        // 6.orderInfo不为空，根据order_id在orderDerate中获取订单减免明细
        List<OrderDerate> orderDerateList = orderDerateMapper.selectList(new LambdaQueryWrapper<OrderDerate>().eq(OrderDerate::getOrderId, orderInfo.getId()));
        // 7.orderDerate不为空，则设置到orderInfo中
        if (!CollectionUtils.isEmpty(orderDerateList)) {
            orderInfo.setOrderDerateList(orderDerateList);
        }
        // 8.根据订单id查询订单详情和订单减免
        // 8.设置支付方式及支付状态
        orderInfo.setOrderStatusName(getOrderStatusName(orderInfo.getOrderStatus()));
        orderInfo.setPayWayName(getPayWayName(orderInfo.getPayWay()));
        // 9.返回封装好的orderInfo
        return orderInfo;
    }

    private String getOrderStatusName(String orderStatus) {
        switch (orderStatus) {
            case SystemConstant.ORDER_STATUS_UNPAID:
                return "未支付";
            case SystemConstant.ORDER_STATUS_PAID:
                return "已支付";
            case SystemConstant.ORDER_STATUS_CANCEL:
                return "已取消";
        }
        return null;
    }

    private String getPayWayName(String payWay) {
        switch (payWay) {
            case SystemConstant.ORDER_PAY_WAY_WEIXIN:
                return "微信支付";
            case SystemConstant.ORDER_PAY_WAY_ALIPAY:
                return "支付宝支付";
            case SystemConstant.ORDER_PAY_WAY_ACCOUNT:
                return "余额支付";
        }
        return null;
    }

    @Transactional
    @Override
    public Map<String, Object> submitOrder(OrderInfoVo orderInfoVo) {
        // 1.判空
        if (orderInfoVo == null) {
            throw new YumaException(ResultCodeEnum.ARGUMENT_VALID_ERROR);
        }
        // 2.验签名
        // 2.1 把对象转成json -> Map
        // JSON.toJSONString(orderInfoVo) 将 Java 对象 orderInfoVo 序列化为 JSON 字符串
        // JSON.parseObject(jsonString, HashMap.class) 将上一步的 JSON 字符串，解析成一个 HashMap<String, Object>
        Map<String, Object> sign = JSON.parseObject(JSON.toJSONString(orderInfoVo), HashMap.class);
        // 2.2 为了验签能通过，把map中验签方式改成微信支付
        sign.put("payWay", SystemConstant.ORDER_PAY_WAY_WEIXIN);
        // 2.3 验签
        SignHelper.checkSign(sign);
        // 3.幂等性：不允许订单重复提交的幂等
        // 3.1写一个lua脚本，如果key存在则删除，返回结果，否则返回0（key不存在，删除失败，都不会让他继续运行）
        String script = """
                 if redis.call('exists',KEYS[1]) == 1 \s
                 then \s
                    return redis.call('del', KEYS[1]) \s
                 else \s
                    return 0 \s
                 end
                """;
        Boolean flag = (Boolean) redisTemplate.execute(
                new DefaultRedisScript(script, Boolean.class),
                List.of(RedisConstant.ORDER_IDEM_PREFIX + orderInfoVo.getTradeNo())
        );
        if (!flag) {
            throw new YumaException(ResultCodeEnum.REPEAT_SUBMIT);
        }
        // 4.判断支付方式
        String payWay = orderInfoVo.getPayWay();
        if (StringUtils.equals(SystemConstant.ORDER_PAY_WAY_WEIXIN, payWay)) {
            // 4.1微信支付：
            // 4.1.1直接保存订单
            this.saveOrder(orderInfoVo);
        } else if (StringUtils.equals(SystemConstant.ORDER_PAY_WAY_ACCOUNT, payWay)) {
            // 4.2余额支付
            // 4.2.1验余额，锁余额
            Long userId = AuthContextHolder.getUserId();
            AccountLockVo lockVo = new AccountLockVo();
            lockVo.setOrderNo(orderInfoVo.getTradeNo());
            lockVo.setUserId(userId);
            lockVo.setAmount(orderInfoVo.getOrderAmount());
            Result<AccountLockResultVo> lockresultVoResult = this.userAccountFeignClient.checkLock(lockVo);
            Assert.notNull(lockresultVoResult, "提交订单模块，账户验锁余额失败");
            AccountLockResultVo resultVo = lockresultVoResult.getData();
            if (ObjectUtils.isEmpty(resultVo)) {
                throw new YumaException(ResultCodeEnum.ACCOUNT_LOCK_ERROR);
            }
            try {
                // 4.2.2保存三张订单
                this.saveOrder(orderInfoVo);
                // 4.2.2.1成功扣减余额
                this.rabbitTemplate.convertAndSend(RabbitConstant.ORDER_EXCHANGE, RabbitConstant.ACCOUNT_MINUS_RK, orderInfoVo.getTradeNo());
            } catch (Exception e) {
                // 4.2.2.2失败解锁余额
                this.rabbitTemplate.convertAndSend(RabbitConstant.ORDER_EXCHANGE, RabbitConstant.ACCOUNT_UNLOCK_RK, orderInfoVo.getTradeNo());
                throw new RuntimeException(e);
            }
        }
        // 订单保存成功之后，用户未来可能不支付，需要定时关单，支付0901状态才能关单
        // TODO 关单（半小时订单支付状态还是0901，就变成0903  关闭订单 1.定时线程池定期线程定时任务 2.Rabbit死信队列）
        this.rabbitTemplate.convertAndSend(RabbitConstant.ORDER_EXCHANGE, RabbitConstant.ORDER_TTL_RK, orderInfoVo.getTradeNo());
        Map<String, Object> map = new HashMap<>();
        map.put("orderNo", orderInfoVo.getTradeNo());
        return map;
    }

    private void saveOrder(OrderInfoVo orderInfoVo) {
        // 先拿到订单详情列表，为了orderInfo.setOrderTitle
        List<OrderDetailVo> orderDetailVoList = orderInfoVo.getOrderDetailVoList();
        // 1.保存订单表
        OrderInfo orderInfo = new OrderInfo();
        BeanUtils.copyProperties(orderInfoVo, orderInfo);
        Long userId = AuthContextHolder.getUserId();
        orderInfo.setUserId(userId);
        // 取第一个订单详情的名称
        if (!CollectionUtils.isEmpty(orderDetailVoList)) {
            orderInfo.setOrderTitle(orderDetailVoList.get(0).getItemName());
        }
        orderInfo.setOrderNo(orderInfoVo.getTradeNo());
        orderInfo.setOrderStatus(SystemConstant.ORDER_STATUS_UNPAID);
        this.orderInfoMapper.insert(orderInfo);

        // 拿到订单ID
        Long orderId = orderInfo.getId();

        // 2.保存订单详情表
        if (!CollectionUtils.isEmpty(orderDetailVoList)) {
            orderDetailVoList.forEach(orderDetailVo -> {
                OrderDetail orderDetail = new OrderDetail();
                BeanUtils.copyProperties(orderDetailVo, orderDetail);
                orderDetail.setOrderId(orderId);
                this.orderDetailMapper.insert(orderDetail);
            });
        }

        // 3.保存订单减免表
        List<OrderDerateVo> orderDerateVoList = orderInfoVo.getOrderDerateVoList();
        if (!CollectionUtils.isEmpty(orderDerateVoList)) {
            orderDerateVoList.forEach(orderDerateVo -> {
                OrderDerate orderDerate = new OrderDerate();
                BeanUtils.copyProperties(orderDerateVo, orderDerate);
                orderDerate.setOrderId(orderId);
                this.orderDerateMapper.insert(orderDerate);
            });
        }
    }

    @Override
    public OrderInfoVo trade(TradeVo tradeVo) {
        return tradeBeanClient.trade(tradeVo);
    }

    /*@Override
    public OrderInfoVo trade(TradeVo tradeVo) {
        switch (tradeVo.getItemType()) {
            case SystemConstant.ORDER_ITEM_TYPE_VIP:
                return vipTrade.trade(tradeVo);
            case SystemConstant.ORDER_ITEM_TYPE_ALBUM:
                return albumTrade.trade(tradeVo);
            case SystemConstant.ORDER_ITEM_TYPE_TRACK:
                return trackTrade.trade(tradeVo);
            default:
                return null;
        }
    }*/

    /*@Override
    public OrderInfoVo trade(TradeVo tradeVo) {
        // 1.创建OrderInfoVo对象
        OrderInfoVo orderInfoVo = new OrderInfoVo();
        // 2.参数判空
        if (tradeVo == null || tradeVo.getItemType() == null || tradeVo.getItemId() == null) {
            throw new YumaException(ResultCodeEnum.ARGUMENT_VALID_ERROR);
        }
        // 3.初始设置订单信息的交易号，支付方式，订单类型，支付状态
        orderInfoVo.setTradeNo(IdWorker.getIdStr());
        orderInfoVo.setPayWay(SystemConstant.ORDER_PAY_WAY_WEIXIN);
        orderInfoVo.setItemType(tradeVo.getItemType());
        // 4.根据itemType判断是什么订单
        String itemType = tradeVo.getItemType();
        //----------4.1 vip订单
        if (SystemConstant.ORDER_ITEM_TYPE_VIP.equals(itemType)) {
            // 5.远程调用vipServiceConfig接口，根据itemId->查询VSC对象
            Result<VipServiceConfig> vipServiceConfigResult = vipServiceConfigFeignClient.getVipServiceConfig(tradeVo.getItemId());
            // 6.判空
            Assert.notNull(vipServiceConfigResult, "生成VIP订单，根据vip配置id查询VIP配置详情");
            VipServiceConfig vipServiceConfig = vipServiceConfigResult.getData();
            Assert.notNull(vipServiceConfig, "生成VIP订单，根据vip配置id查询VIP配置详情");
            // 7.获取Result数据，给原价，减免，总额赋值
            orderInfoVo.setOriginalAmount(vipServiceConfig.getPrice());
            orderInfoVo.setDerateAmount(vipServiceConfig.getPrice().subtract(vipServiceConfig.getDiscountPrice()));
            orderInfoVo.setOrderAmount(vipServiceConfig.getDiscountPrice());

            // 8.封装订单详情集合
            orderInfoVo.setOrderDetailVoList(List.of(
                    new OrderDetailVo()
                            .setItemId(vipServiceConfig.getId())
                            .setItemName("VIP:" + vipServiceConfig.getName())
                            .setItemPrice(vipServiceConfig.getDiscountPrice())
                            .setItemUrl(vipServiceConfig.getImageUrl())
            ));
            // 9.封装订单减免集合
            // 判断减免金额是否大于0，大于0才有减免详情
            if (orderInfoVo.getDerateAmount().compareTo(BigDecimal.ZERO) > 0) {
                orderInfoVo.setOrderDerateVoList(List.of(
                        new OrderDerateVo()
                                .setDerateType(SystemConstant.ORDER_DERATE_VIP_SERVICE_DISCOUNT)
                                .setDerateAmount(orderInfoVo.getDerateAmount())
                                .setRemarks("VIP购买:" + vipServiceConfig.getName())
                ));
            }
        }
        else if (SystemConstant.ORDER_ITEM_TYPE_ALBUM.equals(itemType)) {
            //----------4.2 专辑订单
            // 1.获取登录用户id
            Long userId = AuthContextHolder.getUserId();
            // 2.根据用户id和专辑id查询user_paid_album表中查询是否购买过
            Result<Boolean> paidAlbumResult = userInfoFeignClient.isPaidAlbum(tradeVo.getItemId());
            Assert.notNull(paidAlbumResult, "专辑详情的订单页面，根据用户id和专辑id查询用户是否购买专辑失败");
            Boolean isPaid = paidAlbumResult.getData();
            // 2.1.如果没购买过
            if (!isPaid) {
                // 3.1 根据userId查询userinfo表，是否是没过期的vip用户
                Result<UserInfo> userInfoResult = userInfoFeignClient.getUserById(userId);
                Assert.notNull(userInfoResult, "专辑详情的订单页面，根据用户id查询用户信息失败");
                UserInfo userInfo = userInfoResult.getData();
                Assert.notNull(userInfo, "专辑详情的订单页面，根据用户id查询用户信息失败");
                // 3.2 根据itemId(专辑id)查询专辑的信息
                Result<AlbumInfo> albumInfoResult = albumInfoFeignClient.getAlbumInfo(tradeVo.getItemId());
                Assert.notNull(albumInfoResult, "专辑详情的订单页面，根据专辑id查询专辑信息失败");
                AlbumInfo albumInfo = albumInfoResult.getData();
                Assert.notNull(albumInfo, "专辑详情的订单页面，根据专辑id查询专辑信息失败");
                // 设置原价
                orderInfoVo.setOriginalAmount(albumInfo.getPrice());
                // 3.3 如果是vip用户，orderPrice是vip_discount
                if (userInfo.getIsVip().intValue() == 1 || userInfo.getVipExpireTime().after(new Date())) {
                    if(albumInfo.getVipDiscount().compareTo(BigDecimal.ZERO) > 0) {
                        // 订单价格 ：原价 * vip_discount/10
                        orderInfoVo.setOrderAmount((albumInfo.getVipDiscount().divide(BigDecimal.valueOf(10))).multiply(albumInfo.getPrice()));
                        // 原价 — 订单价格
                        orderInfoVo.setDerateAmount(albumInfo.getPrice().subtract(orderInfoVo.getOrderAmount()));
                    }else {
                        orderInfoVo.setOrderAmount(albumInfo.getPrice());// 订单价格同原价
                        orderInfoVo.setDerateAmount(BigDecimal.ZERO);
                    }
                }else {
                    if(albumInfo.getDiscount().compareTo(BigDecimal.ZERO) > 0) {
                        // 3.3 否则不是vip用户，deratePrice是discount
                        orderInfoVo.setOrderAmount((albumInfo.getDiscount().divide(BigDecimal.valueOf(10))).multiply(albumInfo.getPrice()));
                        // 原价 — 订单价格
                        orderInfoVo.setDerateAmount(albumInfo.getPrice().subtract(orderInfoVo.getOrderAmount()));
                    }else {
                        orderInfoVo.setOrderAmount(albumInfo.getPrice());// 订单价格同原价
                        orderInfoVo.setDerateAmount(BigDecimal.ZERO);
                    }
                }
                // 4.封装订单详情集合
                orderInfoVo.setOrderDetailVoList(List.of(
                        new OrderDetailVo()
                                .setItemId(tradeVo.getItemId())
                                .setItemName(albumInfo.getAlbumTitle())
                                .setItemPrice(albumInfo.getPrice())
                                .setItemUrl(albumInfo.getCoverUrl())
                ));
                // 5.封装订单减免集合
                orderInfoVo.setOrderDerateVoList(List.of(
                        new OrderDerateVo()
                                .setDerateType(SystemConstant.ORDER_DERATE_ALBUM_DISCOUNT)
                                .setDerateAmount(orderInfoVo.getDerateAmount())
                                .setRemarks("专辑:" + albumInfo.getAlbumTitle())
                ));
            }else {
                // 2.2 购买过，抛出不可重复购买异常
                throw new YumaException(ResultCodeEnum.ORDER_SUBMIT_REPEAT);
            }
        }
        else if (SystemConstant.ORDER_ITEM_TYPE_TRACK.equals(itemType)) {
            //----------4.3 声音订单
            // 1.判空 判断值 > 0
            if(tradeVo.getTrackCount() == null || tradeVo.getTrackCount() <= 0){
                // 1.1为空抛异常
                throw new YumaException(ResultCodeEnum.ARGUMENT_VALID_ERROR);
            }
            // 1.2查询本次购买声音列表(album模块远程调用)
            Result<List<TrackInfo>> needBuyListResult = trackInfoFeignClient.findTradeTrackList(tradeVo.getItemId(), tradeVo.getTrackCount());
            // 2.远程调用后断言
            Assert.notNull(needBuyListResult, "声音详情的订单页面，根据声音id查询声音列表失败");
            List<TrackInfo> needBuyList = needBuyListResult.getData();
            Assert.notNull(needBuyList, "声音详情的订单页面，根据声音id查询声音列表失败");
            // 3.根据声音求专辑Id
            Long albumId = needBuyList.get(0).getAlbumId();
            // 4.根据专辑id查询专辑信息
            Result<AlbumInfo> albumInfoResult = albumInfoFeignClient.getAlbumInfo(albumId);
            Assert.notNull(albumInfoResult, "声音详情的订单页面，根据专辑id查询专辑信息失败");
            AlbumInfo albumInfo = albumInfoResult.getData();
            Assert.notNull(albumInfo, "声音详情的订单页面，根据专辑id查询专辑信息失败");
            // 5.封装订单三个价格,声音没有折扣
            orderInfoVo.setOriginalAmount(albumInfo.getPrice().multiply(BigDecimal.valueOf(needBuyList.size())));
            orderInfoVo.setOrderAmount(orderInfoVo.getOriginalAmount());
            orderInfoVo.setDerateAmount(BigDecimal.ZERO);
            // 6.封装订单的详细集合
            orderInfoVo.setOrderDetailVoList(
                    needBuyList.stream().map(trackInfo ->
                            new OrderDetailVo()
                                    .setItemId(trackInfo.getId())
                                    .setItemName(trackInfo.getTrackTitle())
                                    .setItemPrice(albumInfo.getPrice())
                                    .setItemUrl(trackInfo.getCoverUrl())
                    ).collect(Collectors.toList())
            );
            // 不需要封装订单减免集合，声音不打折
        }

        // 10.设置时间戳，创建签名，并设置签名
        orderInfoVo.setTimestamp(SignHelper.getTimestamp());
        // 10.1先把orderInfoVo对象转换成json
        String orderInfoVoJson = JSON.toJSONString(orderInfoVo);
        // 10.2把json转换成HashMap
        Map<String, Object> orderInfoVoMap = JSON.parseObject(orderInfoVoJson, Map.class);
        // 10.3把HashMap转换成Sign
        orderInfoVo.setSign(SignHelper.getSign(orderInfoVoMap));
        // 11.返回订单对象
        return orderInfoVo;
    }*/
}
